home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / hack / 3_1_3 / sys / winnt / winnt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-01  |  2.1 KB  |  138 lines

  1. /*    SCCS Id: @(#)winnt.c     3.1     93/01/31          */
  2. /* Copyright (c) NetHack PC Development Team 1990, 1991, 1992      */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /*
  6.  *  Windows NT system functions.
  7.  *
  8.  *  Initial Creation: Michael Allison - January 31/93
  9.  *
  10.  */
  11.  
  12. #define NEED_VARARGS
  13. #include "hack.h"
  14.  
  15. #ifdef WIN32
  16.  
  17. #include <dos.h>
  18. #include <direct.h>
  19. #include <ctype.h>
  20. #include <windows.h>
  21.  
  22. /*
  23.  * The following WIN32 API routines are used in this file.
  24.  *
  25.  * GetDiskFreeSpace
  26.  * GetVolumeInformation
  27.  * FindFirstFile
  28.  * FindNextFile
  29.  * FindClose
  30.  *
  31.  */
  32.  
  33.  
  34. /* globals required within here */
  35. HANDLE ffhandle = NULL;
  36. WIN32_FIND_DATA ffd;
  37.  
  38.  
  39. char
  40. switchar()
  41. {
  42.  /* Could not locate a WIN32 API call for this- MJA */
  43.     return '-';
  44. }
  45.  
  46. long
  47. freediskspace(path)
  48. char *path;
  49. {
  50.     char tmppath[4];
  51.     DWORD SectorsPerCluster = 0;
  52.     DWORD BytesPerSector = 0;
  53.     DWORD FreeClusters = 0;
  54.     DWORD TotalClusters = 0;
  55.  
  56.     tmppath[0] = *path;
  57.     tmppath[1] = ':';
  58.     tmppath[2] = '\\';
  59.     tmppath[3] = '\0';
  60.     GetDiskFreeSpace(tmppath, &SectorsPerCluster,
  61.             &BytesPerSector,
  62.             &FreeClusters,
  63.             &TotalClusters);
  64.     return (long)(SectorsPerCluster * BytesPerSector *
  65.             FreeClusters);
  66. }
  67.  
  68. /*
  69.  * Functions to get filenames using wildcards
  70.  */
  71. int
  72. findfirst(path)
  73. char *path;
  74. {
  75.     if (ffhandle){
  76.          FindClose(ffhandle);
  77.          ffhandle = NULL;
  78.     }
  79.     ffhandle = FindFirstFile(path,&ffd);
  80.     return 
  81.       (ffhandle == INVALID_HANDLE_VALUE) ? 0 : 1;
  82. }
  83.  
  84. int
  85. findnext() 
  86. {
  87.     return FindNextFile(ffhandle,&ffd) ? 1 : 0;
  88. }
  89.  
  90. char *
  91. foundfile_buffer()
  92. {
  93.     return &ffd.cFileName[0];
  94. }
  95.  
  96. long
  97. filesize(file)
  98. char *file;
  99. {
  100.     if (findfirst(file)) {
  101.         return ((long *)&ffd.nFileSizeLow);
  102.     } else
  103.         return -1L;
  104. }
  105.  
  106. /*
  107.  * Chdrive() changes the default drive.
  108.  */
  109. void
  110. chdrive(str)
  111. char *str;
  112. {
  113.     char *ptr;
  114.     char drive;
  115.     if ((ptr = index(str, ':')) != NULL) 
  116.     {
  117.         drive = toupper(*(ptr - 1));
  118.         _chdrive((drive - 'A') + 1);
  119.     }
  120. }
  121.  
  122. /* NT supports long file names, but does THIS particular volume? */
  123. void
  124. nt_regularize(s)
  125. char *s;
  126. {
  127.     DWORD maxflen;
  128.     int status=0;
  129.     
  130.     status = GetVolumeInformation(NULL,NULL,NULL
  131.             ,NULL,&maxflen,NULL,NULL,NULL);
  132.     if (status)
  133.     {
  134.        if (strlen(s) > maxflen-4) s[maxflen-4] = '\0';
  135.     }
  136. }
  137. #endif /* WIN32 */
  138.